package com.levi.distributedid.controller;

import com.sankuai.inf.leaf.common.Result;
import com.sankuai.inf.leaf.service.SegmentService;
import com.sankuai.inf.leaf.service.SnowflakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IdController {

    @Autowired
    private SegmentService segmentService;

    @Autowired
    private SnowflakeService snowflakeService;

    /**
     * 号段模式
     * @return
     */
    @RequestMapping("segment")
    public Long segment() {
        //leaf-segment-test为leaf生成的数据库的业务字段名称
        return segmentService.getId("leaf-segment-test").getId();
    }

    /**
     * 雪花算法
     * @return
     */
    @RequestMapping("snowflake")
    public Long snowflake() {
        //getId的key不用填，此处为bug
        return snowflakeService.getId("").getId();
    }
}
